<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>title</title>
  <!--按顺序引入-->
  <script src="https://cdn.staticfile.org/react/16.8.4/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.8.4/umd/react-dom.development.js"></script>
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
  <script src="../js/babel.min.js"></script>
  <style>
    body {
      width: 95vw;
      height: 80vh;
      background-color: #2b2b2b;
      color: wheat;
    }
  </style>
</head>
<body>
<div id="app"></div>

<script type="text/babel">
  // 类式组件
  class Weather extends React.Component {
    constructor(props) {
      super(props)
      // 初始化状态
      this.state = {
        isHot: false,
        wind: '微风'
      }
    }

    render() {
      return <h1 onClick={this.changeWeather.bind(this)}>今天天气很{this.state.isHot ? '炎热' : '不炎热'},{this.state.wind}}</h1>
    }

    changeWeather() {
      // 方法只有实例调用时this才会指向当前实例 例如在类中其他方法中:this.changeState()
      // 而上面的H1中this.changeWeather的调用其实不是类的实例调用了

      // 状态不可直接更改 要借助内置的API去更改
      //this.state.isHot = !this.state.isHot 错误写法
      this.setState({isHot: !this.state.isHot})

    }
  }

  // 渲染
  ReactDOM.render(<Weather/>, document.getElementById('app'))
</script>
</body>
</html>
